package com.diyunapp.xilinapp.myindent;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RatingBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.diyunapp.xilinapp.R;
import com.diyunapp.xilinapp.utils.UploadUtilEva;
import com.diyunapp.xilinapp.bean.ReceiveBean;
import com.diyunapp.xilinapp.main.MainActivity;
import com.diyunapp.xilinapp.selfdefine.StatusBarFragmentActivity;
import com.diyunapp.xilinapp.utils.BitmapUtil;
import com.diyunapp.xilinapp.utils.ScrollListViewDisplay;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.squareup.picasso.Picasso;
import com.yuyh.library.imgsel.ImageLoader;
import com.yuyh.library.imgsel.ImgSelActivity;
import com.yuyh.library.imgsel.ImgSelConfig;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ReceiveActivity extends StatusBarFragmentActivity implements View.OnClickListener, UploadUtilEva.OnUploadProcessListener {


    @Bind(R.id.login_tv)
    TextView loginTv;

    @Bind(R.id.go_back1)
    ImageView goBack1;


    @Bind(R.id.evaluation_recylerView)
    ListView evaluationRecylerView;
    @Bind(R.id.star_same)
    RatingBar starSame;
    @Bind(R.id.star_service)
    RatingBar starService;
    @Bind(R.id.star_fahuo)
    RatingBar starFahuo;


    private AlertDialog.Builder builder = null;
    private double desc;
    private double deliver;
    private double service;
    private double goods;
    private String OrderId;
    private String OrderSn;
    private List<ReceiveBean.OrderGoodsBean> evaInfo;
    ;
    private String imgPath;

    private LayoutInflater inflater;
    public String order_id;
    public String gd_id;
    public String st_id;
    public String st_nm;
    public String re_id;
    public String gd_nm;
    public String gd_pi;
    public String gd_ig;
    public String content;
    public String od_sn;
    public String eva_content;
    private ReceiveAdapter receiveAdapter;

    private static final long PICSIZELIMIT = 480000;
    private int REQUEST_CODE = 1;
    private String src1 = null;
    private String src2 = null;
    private String src3 = null;
    private String src4 = null;
    private String src5 = null;
    private int goods_eva_score = 0;
    HashMap<Integer, String> evag_id = new HashMap<Integer, String>();
    List<String> eva = new ArrayList<String>();

    private  List<String> pathList=null;
    private int pzState=99999000;
//    private ReceiveAdapter.ViewHolder viewHolder;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_receive);
        ButterKnife.bind(this);
        OrderId = getIntent().getExtras().getString("OrderId");
//        scrollEvaluation.smoothScrollTo(0, 0);
        View headView;
        headView = findViewById(R.id.receive_menubar_inc);
        super.MenuWidget(headView);
        inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        evaInfo = new ArrayList<>();
        receiveAdapter = new ReceiveAdapter(evaInfo, this);
        evaluationRecylerView.setAdapter(receiveAdapter);
        initView();
        initData();
    }
    private void initData() {


        desc = (double) starSame.getRating();
        service = (double) starService.getRating();
        deliver = (double) starFahuo.getRating();

        starSame.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
            @Override
            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                desc = (int) rating;
            }
        });
        starService.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
            @Override
            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                service = (int) rating;
            }
        });
        starFahuo.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
            @Override
            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                deliver = (int) rating;
            }
        });


    }
    private void initView() {
        String url = "" + MainActivity.url + "act=goods&op=find_all_goods&order_id="
                + OrderId + "";
        Log.i("xiaogaladebug", "url++" + url);
        HttpUtils http = new HttpUtils();
        http.configCurrentHttpCacheExpiry(1000);
        http.send(HttpRequest.HttpMethod.POST, url,
                new RequestCallBack<String>() {
                    @Override
                    public void onLoading(long total, long current, boolean isUploading) {
                    }
                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
//                        bidFreshLv.onRefreshComplete();

                        String resultinfo = responseInfo.result;
                        Log.i("zhangxiaoxidebug", "resultinfo=" + resultinfo);
//                        Logger.e("=================================="+resultinfo);
                        try {
                            JSONObject resultObject = new JSONObject(resultinfo);
                            int result = resultObject.getInt("code");
                            if (result == 200) {
                                JSONObject order_info = resultObject.optJSONObject("order_info");
                                String order_sn = order_info.optString("order_sn");
                                od_sn = order_sn;
                                JSONObject store_info = resultObject.optJSONObject("store_info");
                                String order_id = order_info.optString("order_id");
                                String store_id = order_info.optString("store_id");
                                String store_name = order_info.optString("store_name");
                                order_id = order_id;
                                st_id = store_id;
                                st_nm = store_name;
                                JSONArray order_goods = resultObject.optJSONArray("order_goods");
                                for (int i = 0; i < order_goods.length(); i++) {
                                    JSONObject recordObject = order_goods.optJSONObject(i);
                                    String rec_id = recordObject.optString("rec_id");
                                    re_id = rec_id;
                                    String goods_id = recordObject.optString("goods_id");
                                    gd_id = goods_id;
                                    String goods_name = recordObject.optString("goods_name");
                                    gd_nm = goods_name;
                                    String goods_price = recordObject.optString("goods_price");
                                    gd_pi = goods_price;
                                    String goods_num=recordObject.optString("goods_num");
                                    String goods_image = recordObject.optString("goods_image");
                                    gd_ig = goods_image;
                                    evaInfo.add(new ReceiveBean.OrderGoodsBean(
                                            rec_id, goods_id, goods_name, goods_price,goods_num, goods_image));
                                }
//                                receiveAdapter.setList(info);
                                receiveAdapter.notifyDataSetChanged();
                                ScrollListViewDisplay.setListViewHeightBasedOnChildren(evaluationRecylerView);
                            }
                        } catch (JSONException e) {
                            // TODO Auto-generated catch block
                            toast("查询失败");
                            e.printStackTrace();
                        }
                    }
                    @Override
                    public void onFailure(HttpException error, String msg) {
                        toast("请求失败");
                    }
                });
    }

    @OnClick({R.id.go_back1, R.id.login_tv})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.go_back1:
                finish();
                break;
            case R.id.login_tv:
//                for (int i = 0; i < evaInfo.size(); i++) {
//                    String id=evaInfo.get(i).getGoods_id();
//                    postPic(id);
//                }
//                commit();
                Log.i("zhangxiaoxidebug","1111111");
                docommit();
//                if (src1 != null) {
//                    headPicPost(src1);
//                }
//                if (src2 != null) {
//                    headPicPost(src2);
//                }
//                if (src3 != null) {
//                    headPicPost(src3);
//                }
                break;
            default:
                break;
        }
    }




    private void docommit() {
//        if(eva.get() != null){
//            editText.setText(hashMap.get(position));
//        }
//        xilingou.com/mobile/index.php?act=goods&op=pingjia&order_id=939&comment=商品id|评价内容(多个用逗号隔开)
//                &goods_eva_score=好差评(也是多个逗号隔开好是1中是0差是-1）
//                &store_desccredit=store_servicecredit=store_deliverycredit=&member_id=267&member_name=jqk123
        String message = getMessage();

        String score = getScore();
//        String url = String.format(MainActivity.url+"act=goods&op=pingjia&order_id="+OrderId+"&comment="+message+
//                "&goods_eva_score="+score+"&store_desccredit="+desc+"&store_servicecredit="+service+"&store_deliverycredit="+deliver
//                +"&member_id="+MainActivity.myLogin.getMemberid()+"&member_name="+MainActivity.myLogin.getUsername());
       String url= "http://www.xilingou.com/mobile/index.php?act=goods&op=pingjia";
        RequestParams params = new RequestParams();
        params.addBodyParameter("order_id", OrderId);
        Log.i("zhangxiaoxidebug", "OrderId = " + OrderId);
            params.addBodyParameter("comment",message);
        Log.i("zhangxiaoxidebug", "message = " + message);
         params.addBodyParameter("goods_eva_score",score);
        Log.i("zhangxiaoxidebug", "score = " + score);
        params.addBodyParameter("store_desccredit", String.valueOf(desc));
        Log.i("zhangxiaoxidebug", "desc = " + desc);
        params.addBodyParameter("store_servicecredit", String.valueOf(service));
        Log.i("zhangxiaoxidebug", "service = " + service);
        params.addBodyParameter("store_deliverycredit", String.valueOf(deliver));
        Log.i("zhangxiaoxidebug", "deliver = " + deliver);
        params.addBodyParameter("member_id",MainActivity.myLogin.getMemberid());
        Log.i("zhangxiaoxidebug", "member_id = " + MainActivity.myLogin.getMemberid());
        params.addBodyParameter("member_name",MainActivity.myLogin.getUsername());
        Log.i("zhangxiaoxidebug", "member_name = " + MainActivity.myLogin.getUsername());
        Log.i("zhangxiaoxidebug","uri++"+url);
        HttpUtils http = new HttpUtils();
        http.configCurrentHttpCacheExpiry(1000);
        http.send(HttpRequest.HttpMethod.POST, url, params, new RequestCallBack<String>() {
                    @Override
                    public void onLoading(long total, long current, boolean isUploading) {
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
                        String resultinfo = responseInfo.result;
                        Log.i("zhangxiaoxidebug", "resultinfo=" + resultinfo);
                        try {
                            JSONObject resultObject = new JSONObject(resultinfo);
                            int result = resultObject.getInt("code");
                            if (result == 200) {
                                String data = resultObject.optString("data");
                                if(pzState!=99999000){
                                  for (int i = 0; i < evaInfo.size(); i++) {
                                      int ps=evaInfo.get(i).getPosotion();
                                     String id=evaInfo.get(i).getRec_id();
                                     List<String> list=evaInfo.get(i).getPathList();
                                      if(ps==pzState){
                                          postPic(id,list);
                                      }else{
                                          Log.i("zhangxiaoxidebug","无图片");
                                      }

                                    }
                                }else if(pzState==99999000){
                                    toast(data);
                                    setResult(1);
                                     finish();
                                }
//                                toast(data);
//                                setResult(1);
//                                finish();
                            }
                        } catch (JSONException e) {
                            // TODO Auto-generated catch block
                            toast("查询失败");
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onFailure(HttpException error, String msg) {
                        toast("请求失败");
                    }
                });


    }

    private void postPic(String id,List<String> list) {
        String uploadURL = MainActivity.url+"act=goods&op=evaupload_pic";
        Log.i("zhangxiaoxidebug","-------"+uploadURL);
        UploadUtilEva uploadUtil = UploadUtilEva.getInstance();
        uploadUtil.setOnUploadProcessListener(this); //设置监听器监听上传状态
        Map<String, String> params = new HashMap<String, String>();
        params.put("member_id", MainActivity.myLogin.getMemberid());
        params.put("goods_id",id );

        if(pzState!=99999000) {
            Log.i("zhangxiaoxidebug","-------"+list.size());
            if(list.size()==5){
                src1 = list.get(0);
                src2 = list.get(1);
                src3 = list.get(2);
                src4 = list.get(3);
                src5 = list.get(4);
                uploadUtil.uploadFile( src1,src2,src3,src4,src5,uploadURL,params);
            }else if (list.size()==4){
                 src1 = list.get(0);
                 src2 = list.get(1);
                src3 = list.get(2);
                src4 = list.get(3);
                uploadUtil.uploadFile( src1,src2,src3,src4,uploadURL,params);}
            else
            if (list.size()==3){
                String path1 = list.get(0);
                String path2 = list.get(1);
                String path3 = list.get(2);
                uploadUtil.uploadFile( path1,path2,path3,uploadURL,params);
            }else if (list.size()==2){

                String path1 = list.get(0);
                String path2 = list.get(1);
                uploadUtil.uploadFile( path1,path2,uploadURL,params);
            }else if (list.size()==1){
                String path1 = list.get(0);
                uploadUtil.uploadFile( path1,uploadURL,params);
            }
    }else{
            Log.i("zhangxiaoxi","无照片上传"+id);
        }
    }

    private String getMessage() {

        StringBuffer sayBuffer = new StringBuffer();
        for (int i = 0; i < evaInfo.size(); i++) {
            String sayInfo = String.valueOf(evaInfo.get(i).getEva_content());
        String evainfo=toUtf8String(sayInfo);
            String goodId = evaInfo.get(i).getGoods_id();

            if (!sayInfo.isEmpty()) {
                sayBuffer.append(goodId + "|" + sayInfo + ",");
            }
        }
        if (sayBuffer.length() > 0) {
            sayBuffer.deleteCharAt(sayBuffer.length() - 1);
        }
        Log.i("zhangxiaoxidebug", "sayBuffer = " + sayBuffer.toString());
        return sayBuffer.toString();
    }

    private String getScore() {

        StringBuffer sayBuffer = new StringBuffer();
        for (int i = 0; i < evaInfo.size(); i++) {
            String scoreInfo = String.valueOf(evaInfo.get(i).getEva_scorel());

            String goodId = evaInfo.get(i).getGoods_id();

            if (!scoreInfo.isEmpty()) {
                sayBuffer.append(goodId + "|" + scoreInfo + ",");
            }
        }
        if (sayBuffer.length() > 0) {
            sayBuffer.deleteCharAt(sayBuffer.length() - 1);
        }
        Log.i("zhangxiaoxidebug", "sayBuffer = " + sayBuffer.toString());
        return sayBuffer.toString();
    }
    public static String toUtf8String(String s) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c >= 0 && c <= 255) {
                sb.append(c);
            } else {
                byte[] b;
                try {
                    b = String.valueOf(c).getBytes("utf-8");
                } catch (Exception ex) {
                    System.out.println(ex);
                    b = new byte[0];
                }
                for (int j = 0; j < b.length; j++) {
                    int k = b[j];
                    if (k < 0)
                        k += 256;
                    sb.append("%" + Integer.toHexString(k).toUpperCase());
                }
            }
        }
        return sb.toString();
    }


        @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // 图片选择结果回调
            for (int i = 0; i < evaInfo.size(); i++) {
//                String scoreInfo = String.valueOf(evaInfo.get(i).getEva_scorel());

                int posotion = evaInfo.get(i).getPosotion();

                if (requestCode == posotion && resultCode == RESULT_OK && data != null) {
                    Log.i("xiaogaladebug","++"+posotion);
                    pathList = data.getStringArrayListExtra(ImgSelActivity.INTENT_RESULT);
                    if(pathList.size()!=0){
                        pzState=posotion;
                    }

                    Log.i("zhangxiaoxidebug","11111+"+pathList.size());
                    receiveAdapter.notifyDataSetChanged();
                }
            }

    }

    @Override
    public void onUploadDone(int responseCode, String message) {
        Message myMes = Message.obtain();
        myMes.arg1 = responseCode;
        myMes.obj = message;
        myPicupHandle.sendMessage(myMes);
    }

    @Override
    public void onUploadProcess(int uploadSize) {
        Message myMes = Message.obtain();
        myMes.arg1 = 10;
        myMes.arg2 = uploadSize;
        myPicupHandle.sendMessage(myMes);
    }
    private Handler myPicupHandle = new Handler() {

        public void handleMessage(Message msg) {
            switch (msg.arg1) {
                case UploadUtilEva.UPLOAD_SUCCESS_CODE:
                    toast("提交成功");
                    setResult(1);
                    finish();
                    break;
                case UploadUtilEva.UPLOAD_SERVER_ERROR_CODE:
                    String error = msg.obj.toString();
                    toast(error);
                    break;
                case 10:
                    toasts("正在提交，请稍后...");
                    Log.i("zhangxiaoxidebug","正在上传");
                    break;
                default:
                    break;
            }
        }

    };
    public void toasts(String msg){
        Toast.makeText(this,msg,Toast.LENGTH_LONG).show();
    }
    @Override
    public void initUpload(int fileSize) {

    }

    class ReceiveAdapter extends BaseAdapter implements View.OnClickListener{
        private List<ReceiveBean.OrderGoodsBean> list ;
        private Context context;
        private int REQUEST_CODE = 1;

        public ReceiveAdapter(List<ReceiveBean.OrderGoodsBean> list,Context context) {

            this.list = list;
            this.context = context;
        }
        @Override
        public int getCount() {
            return  list.size();
        }

        @Override
        public Object getItem(int position) {
            return list.get(position);
        }
        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            ViewHolder holder = null;
            if (convertView == null) {
                convertView = LayoutInflater.from(context).inflate(R.layout.item_receive, null);
                holder = new ViewHolder(convertView);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            final ViewHolder viewHolder=holder;
            final ReceiveBean.OrderGoodsBean bean = list.get(position);
//            final ReceiveBean.OrderGoodsBean currentdata = bean.get(position);
            viewHolder.introduceGoods.setText(bean.getGoods_name());
            viewHolder.introducePrice.setText(bean.getGoods_price());
            viewHolder.goodsNum.setText("X"+bean.getGoods_num()+"件");
            //rec_id, goods_id, goods_name, goods_price, goods_image
            String image = bean.getGoods_image();
            Picasso.with(context)
                    .load(image)
                    .resize(200, 200)
                    .centerCrop()
                    .placeholder(R.drawable.list_default)
                    .error(R.drawable.list_default)
                    .into(viewHolder.goodsImage);

            viewHolder.edtPingjia.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }
                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    bean.setEva_content(s.toString());
                }
                @Override
                public void afterTextChanged(Editable s) {
                }
            });
            if (position == pzState) {
                bean.setPathList(pathList);

//                if(pzState==1){
                src1 = null;
                src2 = null;
                src3 = null;
                Log.i("zhangxiaoxidebug","11111+"+pathList.size());
                List<String> list=bean.getPathList();
                Log.i("zhangxiaoxidebug","list"+list.size());
                if (pathList.size() == 1) {
                    src1 = pathList.get(0);
                    viewHolder.image1.setVisibility(View.VISIBLE);
                Bitmap bitmap = BitmapUtil.createThumbnail(src1,100, 100);
                    viewHolder.image1.setImageBitmap(bitmap);
                }else if (pathList.size() == 2) {
                    src1 = pathList.get(0);
                    src2 = pathList.get(1);
                    viewHolder.image1.setVisibility(View.VISIBLE);
                    viewHolder.image2.setVisibility(View.VISIBLE);
                    Bitmap bitmap = BitmapUtil.createThumbnail(src1,100, 100);
                    viewHolder.image1.setImageBitmap(bitmap);
                    Bitmap bitmap1 = BitmapUtil.createThumbnail(src2,  100, 100);
                    viewHolder.image2.setImageBitmap(bitmap1);

                }else if (pathList.size() == 3) {
                    src1 = pathList.get(0);
                    src2 = pathList.get(1);
                    src3 = pathList.get(2);
                    viewHolder.image1.setVisibility(View.VISIBLE);
                    viewHolder.image2.setVisibility(View.VISIBLE);
                    viewHolder.image3.setVisibility(View.VISIBLE);

                    Bitmap bitmap = BitmapUtil.createThumbnail(src1, 100, 100);
                    viewHolder.image1.setImageBitmap(bitmap);

                    Bitmap bitmap1 = BitmapUtil.createThumbnail(src2,  100, 100);
                    viewHolder.image2.setImageBitmap(bitmap1);

                    Bitmap bitmap2 = BitmapUtil.createThumbnail(src3, 100, 100);
                    viewHolder.image3.setImageBitmap(bitmap2);
                }else if (pathList.size() == 4) {
                    src1 = pathList.get(0);
                    src2 = pathList.get(1);
                    src3 = pathList.get(2);
                    src4 = pathList.get(3);
                    viewHolder.image1.setVisibility(View.VISIBLE);
                    viewHolder.image2.setVisibility(View.VISIBLE);
                    viewHolder.image3.setVisibility(View.VISIBLE);
                    viewHolder.image4.setVisibility(View.VISIBLE);
                    Bitmap bitmap = BitmapUtil.createThumbnail(src1, 100, 100);
                    viewHolder.image1.setImageBitmap(bitmap);
                    Bitmap bitmap1 = BitmapUtil.createThumbnail(src2,  100, 100);
                    viewHolder.image2.setImageBitmap(bitmap1);
                    Bitmap bitmap2 = BitmapUtil.createThumbnail(src3, 100, 100);
                    viewHolder.image3.setImageBitmap(bitmap2);
                    Bitmap bitmap3 = BitmapUtil.createThumbnail(src4, 100, 100);
                    viewHolder.image4.setImageBitmap(bitmap3);
                }
                else if (pathList.size() == 5) {
                    src1 = pathList.get(0);
                    src2 = pathList.get(1);
                    src3 = pathList.get(2);
                    src4 = pathList.get(3);
                    src5 = pathList.get(4);
                    viewHolder.image1.setVisibility(View.VISIBLE);
                    viewHolder.image2.setVisibility(View.VISIBLE);
                    viewHolder.image3.setVisibility(View.VISIBLE);
                    viewHolder.image4.setVisibility(View.VISIBLE);
                    viewHolder.image5.setVisibility(View.VISIBLE);
                    Bitmap bitmap = BitmapUtil.createThumbnail(src1, 100, 100);
                    viewHolder.image1.setImageBitmap(bitmap);

                    Bitmap bitmap1 = BitmapUtil.createThumbnail(src2,  100, 100);
                    viewHolder.image2.setImageBitmap(bitmap1);

                    Bitmap bitmap2 = BitmapUtil.createThumbnail(src3, 100, 100);
                    viewHolder.image3.setImageBitmap(bitmap2);
                    Bitmap bitmap3 = BitmapUtil.createThumbnail(src4, 100, 100);
                    viewHolder.image4.setImageBitmap(bitmap3);
                    Bitmap bitmap4 = BitmapUtil.createThumbnail(src5, 100, 100);
                    viewHolder.image5.setImageBitmap(bitmap4);
                }
//                }
            }

            viewHolder.radiogroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                @Override public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
                    if (checkedId == viewHolder.veryGood1.getId()) {
                        bean.setEva_scorel(1);
                    } else if (checkedId == viewHolder.good1.getId()) {
                        bean.setEva_scorel(0);
                    } else if (checkedId == viewHolder.littleGood1.getId()) {
                        bean.setEva_scorel(-1);
                    }
                }
            });
            viewHolder.image1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ImgSelActivity.startActivity((Activity) context, config, position);
                    bean.setPosotion(position);
                }
            });

            return convertView;
        }

        @Override
        public void onClick(View v) {

        }
        private ImageLoader loader = new ImageLoader() {
            @Override
            public void displayImage(Context context, String path, ImageView imageView) {
                // TODO 在这边可以自定义图片加载库来加载 ImageView，例如 Glide、Picasso、ImageLoader 等
                Glide.with(context).load(path).into(imageView);
            }
        };
        ImgSelConfig config = new ImgSelConfig.Builder(loader)
                // 是否多选
                .multiSelect(true)
                .btnTextColor(Color.WHITE)
                // 使用沉浸式状态栏
                .statusBarColor(Color.parseColor("#eb534a"))
                // 返回图标 ResId
                .backResId(R.drawable.goback)
                // 标题
                .title("图片")
                // 标题文字颜色
                .titleColor(Color.WHITE)
                // TitleBar 背景色
                .titleBgColor(Color.parseColor("#eb534a"))
                .needCamera(true)
                // 最大选择图片数量
                .maxNum(5)
                .build();

        ViewHolder viewHolder;

         class ViewHolder {
            @Bind(R.id.goods_image)
            ImageView goodsImage;
            @Bind(R.id.introduce_goods)
            TextView introduceGoods;
            @Bind(R.id.introduce_price)
            TextView introducePrice;
            @Bind(R.id.goods_color)
            TextView goodsColor;
            @Bind(R.id.goods_size)
            TextView goodsSize;
            @Bind(R.id.goods_num)
            TextView goodsNum;
            @Bind(R.id.goods_pingfen)
            TextView goodsPingfen;
            @Bind(R.id.star_goods)
            RatingBar starGoods;
            @Bind(R.id.rel_star_goods)
            RelativeLayout relStarGoods;
            @Bind(R.id.very_good1)
            RadioButton veryGood1;
            @Bind(R.id.good1)
            RadioButton good1;
            @Bind(R.id.little_good1)
            RadioButton littleGood1;
            @Bind(R.id.radiogroup1)
            RadioGroup radiogroup1;
            @Bind(R.id.edt_pingjia)
            EditText edtPingjia;
            @Bind(R.id.image_1)
            ImageView image1;
            @Bind(R.id.image_2)
            ImageView image2;
            @Bind(R.id.image_3)
            ImageView image3;
             @Bind(R.id.image4)
             ImageView image4;
             @Bind(R.id.image5)
             ImageView image5;
            ViewHolder(View view) {
                ButterKnife.bind(this, view);
            }
        }
    }
}